package com.usian.controller;

import com.usian.pojo.TbItem;
import com.usian.pojo.TbItemCat;
import com.usian.pojo.TbItemParam;
import com.usian.service.ItemService;
import com.usian.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("service/")
public class ItemController {
    @Autowired
    private ItemService itemService;

    @RequestMapping("selectItemInfo")
    public TbItem selectItemInfo(Long itemId) {
        return itemService.getId(itemId);
    }

    @RequestMapping("item/selectTbItemAllByPage")
    public PageResult selectTbItemAllByPage(@RequestParam Integer page, @RequestParam Integer rows) {
        return itemService.selectTbItemAllByPage(page, rows);
    }

    @RequestMapping("itemCategory/selectItemCategoryByParentId")
    public List<TbItemCat> selectItemCategoryByParentId(@RequestParam(defaultValue = "0") Long id) {
        return itemService.selectItemCategoryByParentId(id);
    }

    @RequestMapping("itemParam/selectItemParamByItemCatId/{itemCatId}")
    public TbItemParam selectItemParamByItemCatId(@PathVariable Long itemCatId) {
        return itemService.selectItemParamByItemCatId(itemCatId);
    }

    //@RequestMapping("/service/item/insertTbItem")
    @RequestMapping("item/insertTbItem")
    public Integer insertTbItem(@RequestBody TbItem tbItem, String desc, String itemParams) {
        return itemService.insertTbItem(tbItem, desc, itemParams);
    }
    //    @PostMapping("/service/item/deleteItemById")
    @RequestMapping("item/deleteItemById")
    public Integer deleteItemById(Long itemId) {
        return itemService.deleteItemById(itemId);
    }
    @PostMapping("item/delete")
    public Integer delete(Long itemId){
        return itemService.delete(itemId);
    }
    //    @PostMapping("/service/item/findById")
    @PostMapping("/item/findById")
    public Map<String,Object> findById(Long itemId){
      return   itemService.findById(itemId);
    }

    @RequestMapping("item/updateTbItem")
    public Integer update(@RequestBody TbItem tbItem, String desc, String itemParams) {
        return itemService.update(tbItem, desc, itemParams);
    }

    @RequestMapping("itemParam/selectItemParamAll")
    public PageResult selectItemParamAll() {
        return itemService.selectItemParamAll();
    }
    @RequestMapping("itemParam/insertItemParam")
   public Integer insertItemParam(@RequestBody TbItemParam itemParam){
        return itemService.insertItemParam(itemParam);
    }

    @RequestMapping("/itemParam/deleteItemParamById")
   public   Integer deleteItemParamById(@RequestParam Long id){
        return itemService.deleteItemParamById(id);
    }
}